__author__ = 'zoulida'

import datetime
import time

def dayStrToTimeStamp(dayStr = "20190521"):
    timeArray = time.strptime(dayStr, "%Y%m%d")
    timeStamp = int(time.mktime(timeArray))
    return timeStamp

def getDayStr(days):#返回当天日期与days天之前的日期，str类型

    today = datetime.date.today()
    z30daysago = today + datetime.timedelta(days=-days)
    #startstr = '19900101'
    startstr = str(z30daysago.strftime('%Y%m%d'))
    endstr = str(today.strftime('%Y%m%d'))
    return startstr, endstr

def getAheadDayDateform(days):#返回当天日期与days天之前的日期，datetime.date类型
    today = datetime.date.today()
    z30daysago = today + datetime.timedelta(days=-days)
    #print(type(z30daysago))
    return z30daysago

def getDayList(startDay, endDay):#返回日期list
    return

def dateRange(beginDate, endDate):#返回日期list
    dates = []
    dt = datetime.datetime.strptime(beginDate, "%Y%m%d")
    date = beginDate[:]
    while date <= endDate:
        dates.append(date)
        dt = dt + datetime.timedelta(1)
        date = dt.strftime("%Y%m%d")
    return dates

def getTodayDayStr():
    today = datetime.date.today()
    #print(today)
    return  str(today.strftime('%Y%m%d'))

def getTodayNowHourStr():
    #today = datetime.date.today()
    #print(today)
    return  str(datetime.datetime.now().strftime('%Y%m%d%H'))

def getToday_Day_Str():#有横杠的
    today = datetime.date.today()
    #print(today)
    return  str(today.strftime('%Y-%m-%d'))

def getYestodayDayStr():
    yestoday = getAheadDayDateform(1)
    return  str(yestoday.strftime('%Y%m%d'))

def tansformStrToData(date_str = '2023-02-06'):#将字符串类型转化为datetime.date类型

    #date_str = '2017-10-19'
    #print(datetime.date(*map(int, date_str.split('-'))))
    return datetime.date(*map(int, date_str.split('-')))

def tansformStrToDatatime(date_str = '2023-02-06'):
    #from datetime import datetime
    char1 = '-'
    if char1 in date_str:
       date_object = datetime.datetime.strptime(date_str, '%Y-%m-%d')
    else:
       date_object = datetime.datetime.strptime(date_str, '%Y%m%d')
    #print(date_object)
    return date_object

def daystrTodaystr(date_str='2023-02-06'):#将'2023-02-06'转换为'20230206'

    date_object = tansformStrToDatatime(date_str)
    strdate = date_object.strftime("%Y%m%d")
    return strdate

def daystrTodaystrYear_Month_Day(date_str='20230206'):#将'20230206'转换为'2023-02-06'

    date_object = tansformStrToDatatime(date_str)
    strdate = date_object.strftime("%Y-%m-%d")
    return strdate

def datetimeTodaystr(date):#将datetime转换为'20230206'

    #date_object = tansformStrToDatatime(date_str)
    strdate = date.strftime("%Y%m%d")
    return strdate

def nowtime():#当前时间
    return datetime.datetime.now().strftime('%H:%M:%S')

def weeknumber():#当前是哪年的第几周
    #import datetime
    today = datetime.date.today()
    week_number = today.isocalendar()[1]
    print("当前是第{}周".format(week_number))
    strWeek = 'week-' + today.strftime("%Y") + '-' +str(week_number)
    return strWeek


if __name__ == '__main__':
    #print(dayStrToTimeStamp())
    #print(dateRange('20160301', '20190522'))
    #print(getAheadDayDateform(90))
    #print(getYestodayDayStr())
    daystrTodaystr()